package com.bw.vip.page

import android.app.Activity
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.base.path.RouterPath
import com.bw.base.view.BaseActivity
import com.bw.common.view.BaseMvvmActivity
import com.bw.vip.adapter.MemberAdapter
import com.bw.vip.adapter.MemberTypeAdapter
import com.bw.vip.adapter.MemberTypeBean
import com.bw.vip.vm.VipViewModel
import com.bw.viption.R
import com.bw.viption.databinding.ActivityVipBinding
import dagger.hilt.android.AndroidEntryPoint
@Route(path = RouterPath.PATH_VIP_PATH)
@AndroidEntryPoint
class VipActivity : BaseMvvmActivity<ActivityVipBinding>() {

    private val mViewModel :VipViewModel by viewModels()
    override fun getLayoutId(): Int = R.layout.activity_vip
    private val mAdapter = MemberTypeAdapter()
    private val mAdapter2 = MemberAdapter()
    val array = mutableListOf(
        MemberTypeBean("黄金会员",true),
        MemberTypeBean("铂金会员",false),
        MemberTypeBean("钻石会员",false),
        MemberTypeBean("超级会员",false)
    )

    override fun initViews() {
        super.initViews()
        mDataBinding.memberClassify.adapter = mAdapter
        mAdapter.addData(array)
        mDataBinding.memberRight.adapter = mAdapter2
        mViewModel.getVipData(55)

        //选择会员类
        mAdapter.setOnItemClickListener { adapter, view, position ->
            mAdapter.data.forEach {
                it.isCheck = false
            }
            mAdapter.data[position].isCheck = true
            mAdapter.notifyDataSetChanged()
            val type = mAdapter.data[position].type
            when(type){
                "黄金会员" -> {
                    mViewModel.getVipData(55)
                }
                "铂金会员" -> {
                    mViewModel.getVipData(56)
                }
                "钻石会员" -> {
                    mViewModel.getVipData(57)
                }
                "超级会员" -> {
                    mViewModel.getVipData(58)
                }
            }
        }


    }


    override fun loadData() {
        super.loadData()
        mViewModel.mVipSuccess.observe(this){
            mAdapter2.data.clear()
            mAdapter2.data.add(it)
            mAdapter2.notifyDataSetChanged()
        }
    }



}